package com.example.lib.socket;

public class MysendClient extends Thread{
    public static final String TAG = "MysendClient";
    public MyClientSocket cs;
    public MysendClient(MyClientSocket cs){
      this.cs=cs;

    }

    @Override
    public void run() {
        SentData();
    }
    public  void SentData() {
        try {
            long timestamp = System.currentTimeMillis();
            while (true){


               if (cs.data==null){
                  sleep(1000);
                   long ctimestamp = System.currentTimeMillis();
                   if ((ctimestamp-timestamp)>59){
                       timestamp=ctimestamp;
                       byte[] bs=new byte[3];
                       bs[0]=3;
                       bs[1]=3;
                       bs[2]=3;
                       cs.out.write(bs);
                       cs.out.flush();
                       System.out.println("client send ping is ok");
                   }

               }else{
                   HeadData hd=new HeadData();
                   hd.status=3;
                   hd.dataLong=cs.data.length();
                   byte[] bs= MySocketData.getHeadByte(hd);
                   cs.out.write(bs);
                   cs.out.flush();
                   if (cs.status==2){
                       cs.out.write(cs.data.getBytes());
                       cs.out.flush();

                   }

                   cs.data=null;
                   OcrData od=new OcrData();
                   od.msgId=8;
                   od.ImgStr="发送数据成功";
                   cs.call.MyCall(od);
                   System.out.println("client send is ok");
            }

        }
        } catch (Exception e) {
            OcrData od=new OcrData();
            od.msgId=7;
            od.ImgStr="发送数据失败";
            cs.call.MyCall(od);
            System.out.println("client send is false ");
            e.printStackTrace();
        }
    }
}
